package com.itheima.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.domain.Category;
import com.itheima.factory.BeanFactory;
import com.itheima.service.CategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/CategoryServlet")
public class CategoryServlet extends BaseServlet {
    CategoryService categoryService = (CategoryService) BeanFactory.getBean("categoryService");

    //作为模板使用
    protected void dopost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
    // ajax查询所有
    protected void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.调用service查询
        List<Category> categoryList = categoryService.findAll();
        // 2.转为json，响应到客户端
        javaToJsonWriteClient(categoryList, response);
    }


}
